package com.example.teesystem.mapper;

import com.example.teesystem.entity.Boat;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.teesystem.entity.vo.boatGame.BoatRoom;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.Date;
import java.util.List;

/**
* @author 12510
* @description 针对表【t_boat】的数据库操作Mapper
* @createDate 2022-11-26 12:46:51
* @Entity com.example.teesystem.entity.Boat
*/
@Mapper
public interface BoatMapper extends BaseMapper<Boat> {
    @Select("select count(*) as num ,room_id as roomId from t_boat where is_delete = 0 and course_id = #{courseId} group by room_id")
    List<BoatRoom> getBoatRoom(int courseId);
    @Select("select * from t_boat where uid = #{uid} and is_delete = 0 and course_id = #{courseId}")
    Boat getBoatByUid(int uid,int courseId);
    @Select("select * from t_boat where is_delete = 0 and room_id = #{roomId} order by score")
    List<Boat> getBoatByRoomId(String roomId);

    @Update("update t_boat set score=#{score},total_num = #{totalNum},right_num=#{rightNum} where uid = #{uid} and room_id = #{roomId}")
    void updatePlayer(int score,int uid,String roomId,int totalNum,int rightNum);

    @Select("select * from t_boat where room_id = #{roomId} and is_finish = 1")
    List<Boat> getFinishPlayer(String roomId);

    @Update("update t_boat set is_finish = 1,score=#{score},total_num = #{totalNum},right_num=#{rightNum},is_delete = 1 where uid = #{uid} and room_id= #{roomId}")
    void updateFinish(int score,int uid,String roomId,int totalNum,int rightNum);
    @Update("UPDATE t_boat set is_delete = 1 WHERE TIMESTAMPDIFF(SECOND,update_time,#{date}) >= 70")
    void updateBoatDelete(Date date);
    @Update("update t_boat set is_finish = 1,is_delete = 1 where room_id=  #{roomId}")
    void updateRoomFinish(String roomId);

    @Delete("delete from t_boat where is_delete = 1")
    void delete();
}




